package org.point.dao.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.point.common.dao.impl.BaseDaoImpl;
import org.point.common.util.DoPage;
import org.point.dao.ProductTypeDao;
import org.point.domain.ProductType;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: ProductTypeDaoImpl
 * @Description: TODO(商品分类数据实现类)
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午3:44:30
 *
 */
@Repository("productTypeDao")
public class ProductTypeDaoImpl extends BaseDaoImpl<ProductType, Serializable> implements ProductTypeDao {

	/**
	 * 利用反射，获取mapper.xml的namespace
	 * <p>
	 * Title:
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 */
	public ProductTypeDaoImpl() {
		namespace = super.getNamespace();
	}

	// 根据会员查询所属商品分类信息
	private static final String SQLID_SEARCHFORMEM = "search_For_Mem";
	// 根据会员查询所属商品分类信息
	private static final String SQLID_SEARCHFORMEMPAGE = "search_For_Mem_page";
	// 根据会员查询所属商品分类信息记录
	private static final String SQLID_SEARCHFORMEMCOUNT = "search_For_Mem_count";
	// 新增商品分类信息
	private static final String SQLID_INSERTPT = "insert_PT";
	// 修改商品分类信息状态
	private static final String SQLID_UPDSTATUS = "upd_Status";
	//根据ID查找商品分类信息
	private static final String SQLID_SEARCHFORID = "search_for_id";
	
	private static final String SQLID_DELPROTY = "delProTy";
	

	public List<ProductType> searchForMem(Map<String, Object> map) {
		List<ProductType> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_SEARCHFORMEM, map);
		} catch (Exception e) {
			throw new RuntimeException("查询数据总记录数错误！", e);
		}
		return records;
	}
	//根据商品id 查找商品分类信息
	public ProductType searchForId(Map<String, Object> map) {
		ProductType records = null;
		try {
			records = getSqlSession().selectOne(namespace + SQLID_SEARCHFORID, map);
		} catch (Exception e) {
			throw new RuntimeException("查询数据总记录数错误！", e);
		}
		return records;
	}
	
	public List<ProductType> searchForMem(DoPage<ProductType> page) {
		List<ProductType> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_SEARCHFORMEMPAGE, page);
		} catch (Exception e) {
			throw new RuntimeException("查询数据总记录数错误！", e);
		}
		return records;
	}

	public Integer searchForMemCount(DoPage<ProductType> page) {
		Integer result = 0;
		try {
			result = getSqlSession().selectOne(namespace + SQLID_SEARCHFORMEMCOUNT, page);
			System.out.println(namespace + SQLID_SEARCHFORMEMCOUNT+"*********");
		} catch (Exception e) {
			throw new RuntimeException("查询数据总记录数错误！", e);
		}
		return result;
	}

	public Integer insertPT(ProductType record) {
		Integer result = 0;
		try {
			result = getSqlSession().insert(namespace + SQLID_INSERTPT, record);
		} catch (Exception e) {
			throw new RuntimeException("新增数据错误！", e);
		}
		return result;
	}

	public Integer updStatus(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_UPDSTATUS, map);
		} catch (Exception e) {
			throw new RuntimeException("修改数据错误！", e);
		}
		return result;
	}
	public Integer delProTy(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_DELPROTY, map);
		} catch (Exception e) {
			throw new RuntimeException("修改数据错误！", e);
		}
		return result;
	}

}
